package com.yanqu.road.server.cmd.inn;

import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.pb.inn.InnProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.inn.InnModule;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_INN_COOK_START, desc = "开始烹饪")
public class InnCookStartCmd extends AbstractCommand {

    private int dishesId;
    private int patronsId;
    private int dishesNum;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        InnProto.InnCookStartReqMsg reqMsg = InnProto.InnCookStartReqMsg.parseFrom(packet.getBytes());

        dishesId = reqMsg.getDishesId();
        dishesNum = reqMsg.getDishesNum();
        patronsId = reqMsg.getPatronsId();

        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        if (!SystemOpenMgr.systemOpen(player, eSystemId.Inn.getValue())) {
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }
        InnModule module = player.getModule(InnModule.class);
        if (null != module) {
            ret = module.startCook(dishesId, patronsId, dishesNum);
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        InnProto.InnCookStartRspMsg.Builder respMsg = InnProto.InnCookStartRspMsg.newBuilder().setRet(ret);
        InnProto.InnDetailInfoMsg innInfo = player.getModule(InnModule.class).getInnInfo();
        if (innInfo != null && ret == 0) {
            respMsg.setInnDetailInfo(innInfo);
        }
        player.sendPacket(Protocol.U_INN_COOK_START, respMsg);
    }
}
